---@class GT.ui.control.scroll_view : GT.ui
---@field u table<RoleID,GT.ui.control.scroll_view> 玩家独立数据驱动
---@field binding GT.ui.control.scroll_view
GT.ui.control.scroll_view = class(GT.ui, false)


---@class ui_data_scroll_view : ui_data
---@field margin Int32 间距
---@field img Int32 间距
ui_data_scroll_view = {
    
}

--- 创建列表
---@param data ui_data_scroll_view
---@return GT.ui.control.scroll_view
function GT.ui.control.scroll_view:ctor(data)
    data.class=GT.ui.control.scroll_view
    if data.uid ~= nil then
        super(self, data)
    else
        data.u_type = GT.ui.type.list
        self.margin = data.margin
        self.img = data.img
        --创建控件
        super(self, data)
        if self.margin ~= nil then
            self:set_ui_comp_margin(self.margin)
        end
        if self.img ~= nil then
            self:set_image(self.img)
        end
        
    end

    self:scroll_view_watch()
    return self
end

--监听绑定
---@return GT.ui.control.scroll_view
function GT.ui.control.scroll_view:scroll_view_watch()
    ---@type bind_data
    local data = {
        {
            key = "margin",
            func = function(val, old)
                self.margin = val
                self:set_ui_comp_margin(self.margin)
            end
        },
        {
            key = "img",
            func = function(val, old)
                self.img = val
                self:set_image(self.img)
            end
        }
    }

    self.bind:add(data)
    return self
end

--- 添加下拉框选项
---@param role Role 玩家
---@param comp_id Str 下拉框
---@param text Str 名称
---@param value Str 值
function GT.ui.control.scroll_view:add_combo_item(text, value)
    game_api.add_combo_item(self.player.player , self.uid, text, value)
    return self
end

--- 设置下拉框默认文本
---@param role Role 玩家
---@param comp_id Str 下拉框
---@param text Str 默认文本
function GT.ui.control.scroll_view:set_combo_text(text)
    game_api.set_combo_text(self.player.player , self.uid, text)
    return self
end

--- 获取下拉框当前值
---@param comp_id Str 下拉框
---@return Str
function GT.ui.control.scroll_view:get_cur_value()
    return game_api.get_combo_box_cur_value(self.uid)
end

--- 设置ui列表组件间距
---@param margin Int32 间距
function GT.ui.control.scroll_view:set_ui_comp_margin(margin)
    game_api.set_ui_comp_margin(self.player.player , self.uid,margin)
    return self
end

--- 设置ui组件图片
---@param image_id Int32 图片id
---@return GT.ui.control.scroll_view
function GT.ui.control.scroll_view:set_image(image_id)
    game_api.set_ui_comp_image(self.player.player , self.uid, image_id)
    return self
end

--- 清空下拉框
function GT.ui.control.scroll_view:clear_item()
    game_api.clear_combo_box(self.player.player , self.uid)
end